package com.example.demo.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.example.demo.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.servlet.Filter;
import java.util.ArrayList;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/4/16/10:23
 */
@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean<Filter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new MyFilter());
        filterFilterRegistrationBean.setName("myFilter");
        filterFilterRegistrationBean.addUrlPatterns("/");
        return filterFilterRegistrationBean;
    }


    @Bean
    public Docket docket(){
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .groupName("tian")//设置组名
                .apiInfo(apiInfo()) //文档信息介绍
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))//为哪个bao生成接口文档
                .build()
                ;
        return docket;
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;
    }

    private ApiInfo apiInfo(){
        Contact DEFAULT_CONTACT = new Contact("田磊", "http://www.jd.com", "1725554631@qq.com");
        ApiInfo info = new ApiInfo("测试swagger文档", "测试swagger文档", "1.0", "http://www.baidu.com",
                DEFAULT_CONTACT, "礼悦莘恬", "http://www.aaa.comm", new ArrayList<VendorExtension>());
        return info;
    }

}
